<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@include file="../common/base_body_header.jsp" %>
<%@include file="../common/navbar.jsp" %>
<%@include file="../common/page_content_pre.jsp" %>

<div class="page-content">
    <div class="row">
        <div class="col-xs-12">
            <form class="form-horizontal" role="form" action="${GLOBAL.basePath}/houseInfo/list" method="post">
                <fieldset>
                    <div class="form-group">
                        <label class="col-sm-1 control-label" for="houseNo">编号</label>

                        <div class="col-sm-2">
                            <input class="form-control" id="houseNo" type="text" name="houseNo" placeholder="房源编号"
                                   value="${houseInfo.houseNo}"/>
                        </div>

                        <label class="col-sm-1 control-label">区域</label>

                        <div class="col-sm-2">
                            <select class="input-xlarge" name="district">
                                <option value="" selected=selected>全部</option>
                                <c:forEach items="${fns:getDictList('district')}" var="item">
                                    <option value="${item.name}"
                                            <c:if test="${item.name == houseInfo.district}">selected</c:if>>${item.value}</option>
                                </c:forEach>
                            </select>
                        </div>
                        <label class="col-sm-1 control-label">所属小区</label>

                        <div class="col-sm-2">
                            <select class="input-xlarge" name="nbhId" id="nhbId">
                                <option value="" selected=selected>全部</option>
                                <c:forEach items="${neighborhoodList}" var="item">
                                    <option value="${item.nbhId}"
                                            <c:if test="${item.nbhId == houseInfo.nbhId}">selected</c:if>>${item.nbhName}</option>
                                </c:forEach>
                            </select>
                        </div>
                        <div class="col-sm-2">
                            <button class="btn btn-primary btn-sm" onsubmit="return false;">
                                查询
                                <i class="icon-search align-top bigger-125 icon-on-right"></i>
                            </button>
                        </div>
                    </div>
                </fieldset>
                <fieldset>
                    <div class="form-group">
                        <label class="col-sm-1 control-label">类别</label>

                        <div class="col-sm-2">
                            <select class="input-xlarge" name="houseType">
                                <option value="" selected=selected>全部</option>
                                <c:forEach items="${fns:getDictList('house_type')}" var="item">
                                    <option value="${item.name}"
                                            <c:if test="${item.name == houseInfo.houseType}">selected</c:if>>${item.value}</option>
                                </c:forEach>
                            </select>
                        </div>
                        <label class="col-sm-1 control-label">状态</label>

                        <div class="col-sm-2">
                            <select class="input-xlarge" name="houseStatus">
                                <option value="" selected=selected>全部</option>
                                <c:forEach items="${fns:getDictList('house_status')}" var="item">
                                    <option value="${item.name}"
                                            <c:if test="${item.name == houseInfo.houseStatus}">selected</c:if>>${item.value}</option>
                                </c:forEach>
                            </select>
                        </div>
                        <label class="col-sm-1 control-label">钥匙</label>
                        <div class="col-sm-2">
                            <select class="input-xlarge" name="keyFlag">
                                <option value="" selected=selected>全部</option>
                                <option value="0" <c:if test="${houseInfo.keyFlag == '0'}">selected</c:if>>无</option>
                                <option value="1" <c:if test="${houseInfo.keyFlag == '1'}">selected</c:if>>有</option>
                            </select>
                        </div>
                        <label class="col-sm-1 control-label">聚焦</label>

                        <div class="col-sm-2">
                            <select class="input-xlarge" name="focusFlag">
                                <option value="" selected=selected>全部</option>
                                <option value="0" <c:if test="${houseInfo.focusFlag == '0'}">selected</c:if>>否</option>
                                <option value="1" <c:if test="${houseInfo.focusFlag == '1'}">selected</c:if>>是</option>
                            </select>
                        </div>
                    </div>
                </fieldset>
            </form>
        </div>
        <shiro:hasPermission name="houseInfo:edit">
            <div class="col-sm-12">
                <button class="btn btn-xs btn-success" id="add_btn">
                    添加别墅
                    <i class="icon-plus align-top bigger-125 icon-on-right"></i>
                </button>
                &nbsp;
                <button class="btn btn-xs btn-success" id="add_btn_hz">
                    添加豪宅
                    <i class="icon-plus align-top bigger-125 icon-on-right"></i>
                </button>
            </div>
        </shiro:hasPermission>
        <div class="col-xs-12">
            <div class="table-responsive">
                <table id="list-table" class="table table-striped table-bordered table-hover" width="100%">
                    <thead>
                    <tr>
                        <th class="hidden-480">编号</th>
                        <th class="hidden-480">小区</th>
                        <th class="hidden-480" width="120px">名称</th>
                        <th class="hidden-480">楼栋</th>
                        <th class="hidden-480">单元</th>
                        <th class="hidden-480">室号</th>
                        <th class="hidden-480" width="90px">类别</th>
                        <th class="hidden-480">面积</th>
                        <th class="hidden-280" width="90px">总价（万）</th>
                        <th class="hidden-480">状态</th>
                        <th class="hidden-480">钥匙</th>
                        <th class="hidden-480">跟进日期</th>
                        <th class="hidden-480">聚焦</th>
                        <th class="hidden-480">收藏</th>
                        <th>房源操作</th>
                        <th>操作</th>
                    </tr>
                    </thead>
                </table>
            </div>
        </div>
    </div>
</div>

<%@include file="../common/page_content_suf.jsp" %>
<%@include file="../common/script.jsp" %>

<script type="text/javascript">
    var houseInfoListTable;
    var staus;
    var focus;
    var houseType;
    jQuery(function ($) {

        $("#add_btn").on("click", function () {
            addClick();
        });

        $("#add_btn_hz").on("click", function () {
            addHzClick();
        });

        $('.date-picker').datepicker({autoclose: true}).next().on(ace.click_event, function () {
            $(this).prev().focus();
        });

        houseInfoListTable = $('#list-table').dataTable({
            "sAjaxSource": "${GLOBAL.basePath}/houseInfo/asynList",
            "fnServerData": function (sSource, aDataSet, fnCallback) {
                $.ajax({
                    "dataType": 'json',
                    "type": "POST",
                    "url": sSource,
                    "data": aDataSet,
                    "success": fnCallback,
                    "beforeSend": function (XMLHttpRequest) {
                        layer.load();
                    },
                    "complete": function (XMLHttpRequest, textStatus) {
                        layer.closeAll('loading');
                    }
                });
            },
            "fnServerParams": function (aoData) {//向服务器传额外的参数
                <c:if test="${not empty aoData}">
                aoData.push(${aoData});
                </c:if>
            },
            "bSort": false,
            "bFilter": false,
            "bServerSide": true,
            "bProcessing": false,
            "bLengthChange": false,
            "bSearching": false,
            "sProcessing": "${GLOBAL.staticImagePath}/loading.gif' />",
            "oLanguage": {
                "sInfo": "从 _START_ 到 _END_ /共 _TOTAL_ 条",
                "sInfoEmpty": "No data"
            },
            "aoColumns": [
                {"mDataProp": "houseNo", "sWidth": "60px"},
                {"mDataProp": "nbhName", "sWidth": "120px"},
                {"mDataProp": "title"},
                {"mDataProp": "buildingNo"},
                {"mDataProp": "unitNo"},
                {"mDataProp": "roomNo"},
                {
                    "mDataProp": "houseType", "mRender": function (data, type, full) {
                        if (data == 1) {
                            houseType = "bsdetail";
                            return "二手别墅";
                        } else if (data == 2) {
                            houseType = "hzdetail";
                            return "二手豪宅";
                            houseType = "xpdetail";
                        } else {
                            return "新楼盘";
                        }
                    }
                },
                {"mDataProp": "totalArea"},
                {"mDataProp": "totalPrice"},
                {
                    "mDataProp": "houseStatus", "mRender": function (data, type, full) {
                        if (data == 1) {
                            return "<span class='label label-sm label-info'>新增房</span>";
                        } else if (data == 2) {
                            return "<span class='label label-sm label-warning'>在售</span>";
                        } else if (data == 3) {
                            return "<span class='label label-sm label-success'>已售</span>";
                        } else if (data == 4) {
                            return "<span class='label label-sm label-default'>无效</span>";
                        }
                    }
                },
                {
                    "mDataProp": "keyFlag", "mRender": function (data, type, full) {
                        if (data == 1) {
                            return "<span class='label label-sm label-success'>有</span>";
                        } else {
                            return "<span class='label label-sm label-info'>无</span>";
                        }
                    }
                },
                {"mDataProp": "followLastDate"},
                {
                    "mDataProp": "focusFlag", "mRender": function (data, type, full) {
                        focus = data;
                        if (data == 1) {
                            return "<span class='label label-sm label-success'>是</span>";
                        } else {
                            return "<span class='label label-sm label-info'>否</span>";
                        }
                    }
                },
                {
                    "mDataProp": "isCollection", "mRender": function (data, type, full) {
                        staus = data;
                        if (data == 0) {
                            return "<span class='label label-sm label-success'>是</span>";
                        } else if (data == 1) {
                            return "<span class='label label-sm label-info'>否</span>";
                        } else {
                            return "<span class='label label-sm label-info'>否</span>";
                        }
                    }
                },
                {
                    "mDataProp": "houseId", "sWidth": "120px", "mRender": function (data, type, full) {
                        if (staus == 0) {
                            if (focus == 0) {
                                return "<div class='visible-md visible-lg hidden-sm hidden-xs btn-group'>"
                                    + "<shiro:hasPermission name='follow:view'><button class='btn btn-xs btn-primary' pkId='" + data + "' onclick='followClick(this)'>"
                                    + "跟进"
                                    + "</button></shiro:hasPermission>"
                                    + "<shiro:hasPermission name='inspectNote:view'><button class='football-del btn btn-xs btn-success' pkId='" + data + "' onclick='inspectNoteClick(this)'>"
                                    + "带看"
                                    + "</button></shiro:hasPermission>"
                                    + "<shiro:hasPermission name='houseInfo:uncollection'><button class='football-edit btn btn-xs btn-info' pkId='" + data + "' onclick='uncollectionClick(this)'>"
                                    + "已收藏"
                                    + "</button></shiro:hasPermission>"
                                    + "<shiro:hasPermission name='houseInfo:focus'><button class='football-del btn btn-xs btn-info' pkId='" + data + "' onclick='focusingClick(this)'>"
                                    + "未聚焦"
                                    + "</button></shiro:hasPermission>"
                                    + "</div>";
                            } else {
                                return "<div class='visible-md visible-lg hidden-sm hidden-xs btn-group'>"
                                    + "<shiro:hasPermission name='follow:view'><button class='btn btn-xs btn-primary' pkId='" + data + "' onclick='followClick(this)'>"
                                    + "跟进"
                                    + "</button></shiro:hasPermission>"
                                    + "<shiro:hasPermission name='inspectNote:view'><button class='football-del btn btn-xs btn-success' pkId='" + data + "' onclick='inspectNoteClick(this)'>"
                                    + "带看"
                                    + "</button></shiro:hasPermission>"
                                    + "<shiro:hasPermission name='houseInfo:uncollection'><button class='football-edit btn btn-xs btn-info' pkId='" + data + "' onclick='uncollectionClick(this)'>"
                                    + "已收藏"
                                    + "</button></shiro:hasPermission>"
                                    + "<shiro:hasPermission name='houseInfo:focus'><button class='football-del btn btn-xs btn-info' pkId='" + data + "' onclick='unfocusingClick(this)'>"
                                    + "已聚焦"
                                    + "</button></shiro:hasPermission>"
                                    + "</div>";
                            }
                        } else {
                            if (focus == 0) {
                                return "<div class='visible-md visible-lg hidden-sm hidden-xs btn-group'>"
                                    + "<shiro:hasPermission name='follow:view'><button class='btn btn-xs btn-primary' pkId='" + data + "' onclick='followClick(this)'>"
                                    + "跟进"
                                    + "</button></shiro:hasPermission>"
                                    + "<shiro:hasPermission name='inspectNote:view'><button class='football-del btn btn-xs btn-success' pkId='" + data + "' onclick='inspectNoteClick(this)'>"
                                    + "带看"
                                    + "</button></shiro:hasPermission>"
                                    + "<shiro:hasPermission name='houseInfo:collection'><button class='football-edit btn btn-xs btn-info' pkId='" + data + "' onclick='collectionClick(this)'>"
                                    + "未收藏"
                                    + "</button></shiro:hasPermission>"
                                    + "<shiro:hasPermission name='houseInfo:focus'><button class='football-del btn btn-xs btn-info' pkId='" + data + "' onclick='focusingClick(this)'>"
                                    + "未聚焦"
                                    + "</button></shiro:hasPermission>"
                                    + "</div>";
                            } else {
                                return "<div class='visible-md visible-lg hidden-sm hidden-xs btn-group'>"
                                    + "<shiro:hasPermission name='follow:view'><button class='btn btn-xs btn-primary' pkId='" + data + "' onclick='followClick(this)'>"
                                    + "跟进"
                                    + "</button></shiro:hasPermission>"
                                    + "<shiro:hasPermission name='inspectNote:view'><button class='football-del btn btn-xs btn-success' pkId='" + data + "' onclick='inspectNoteClick(this)'>"
                                    + "带看"
                                    + "</button></shiro:hasPermission>"
                                    + "<shiro:hasPermission name='houseInfo:collection'><button class='football-edit btn btn-xs btn-info' pkId='" + data + "' onclick='collectionClick(this)'>"
                                    + "未收藏"
                                    + "</button></shiro:hasPermission>"
                                    + "<shiro:hasPermission name='houseInfo:focus'><button class='football-del btn btn-xs btn-info' pkId='" + data + "' onclick='unfocusingClick(this)'>"
                                    + "已聚焦"
                                    + "</button></shiro:hasPermission>"
                                    + "</div>";
                            }
                        }
                    }
                },
                {
                    "mDataProp": "houseId", "sWidth": "90px", "mRender": function (data, type, full) {
                        return "<div class='visible-md visible-lg hidden-sm hidden-xs btn-group'>"
                            + "<shiro:hasPermission name='houseInfo:delete'><button class='football-del btn btn-xs btn-danger' pkId='" + data + "' onclick='delClick(this)'>"
                            + "<i class='icon-trash bigger-120'></i>"
                            + "</button></shiro:hasPermission>"
                            + "<shiro:hasPermission name='houseInfo:detail'><button class='football-del btn btn-xs btn-success'>"
                            + "<a href =" + '${GLOBAL.pagePath}' + houseType + '/' + data + " target='_blank'><i class='icon-list-ul bigger-120'></i></a>"
                            + "</button></shiro:hasPermission>"
                            + "<shiro:hasPermission name='phone:view'><button class='football-del btn btn-xs btn-info' pkId='" + data + "' onclick='phone(this)'>"
                            + "业主电话"
                            + "</button></shiro:hasPermission>"
                            + "</div>";

                    }
                }
            ]
        });

    });

    var addClick = function () {
        document.location.href = "${GLOBAL.basePath}/houseInfo/add?type=1&nbhId=" + '${houseInfo.nbhId}';
    };

    var addHzClick = function () {
        document.location.href = "${GLOBAL.basePath}/houseInfo/add?type=2&nbhId=" + '${houseInfo.nbhId}';
    };

    var editClick = function (obj) {
        document.location.href = "${GLOBAL.basePath}/houseInfo/edit?houseId=" + $(obj).attr("pkId");
    };

    <%--var detailClick = function (obj) {--%>
    <%--document.location.href = "${GLOBAL.basePath}/houseInfo/detail?houseId=" + $(obj).attr("pkId");--%>
    <%--};--%>

    var followClick = function (obj) {
        document.location.href = "${GLOBAL.basePath}/follow/list?relationType=1&relationId=" + $(obj).attr("pkId");
    }

    var inspectNoteClick = function (obj) {
        document.location.href = "${GLOBAL.basePath}/inspectNote/list?relationType=1&relationId=" + $(obj).attr("pkId");
    }

    var collectionClick = function (obj) {
        layer.confirm("确定要收藏吗？", {
            title: '提示',
            btn: ['确认', '取消'], //按钮
            area: ['auto', 'auto'] //宽高
        }, function () {
            var result = ART.mAjax("${GLOBAL.basePath}/houseInfo/collection", "POST", {houseId: $(obj).attr("pkId")});
            layer.alert("收藏成功", {icon: 1, title: '提示', btn: ['OK']});
            houseInfoListTable.fnDraw();
        })
    }

    var uncollectionClick = function (obj) {
        layer.confirm("确定要取消收藏吗？", {
            title: '提示',
            btn: ['确认', '取消'], //按钮
            area: ['auto', 'auto'] //宽高
        }, function () {
            var result = ART.mAjax("${GLOBAL.basePath}/houseInfo/uncollection", "POST", {houseId: $(obj).attr("pkId")});
            layer.alert("取消成功", {icon: 1, title: '提示', btn: ['OK']});
            houseInfoListTable.fnDraw();
        })
    }

    var delClick = function (obj) {
        layer.confirm("确定要删除吗？", {
            title: '提示',
            btn: ['确认', '取消'], //按钮
            area: ['auto', 'auto'] //宽高
        }, function () {
            var result = ART.mAjax("${GLOBAL.basePath}/houseInfo/delete", "POST", {houseId: $(obj).attr("pkId")});
            layer.alert("编辑成功", {icon: 1, title: '提示', btn: ['OK']});
            houseInfoListTable.fnDraw();
        })
    }

    var focusingClick = function (obj) {
        layer.confirm("确定要聚焦吗？", {
            title: '提示',
            btn: ['确认', '取消'], //按钮
            area: ['auto', 'auto'] //宽高
        }, function () {
            var result = ART.mAjax("${GLOBAL.basePath}/houseInfo/focusing", "POST", {houseId: $(obj).attr("pkId")});
            layer.alert("聚焦成功", {icon: 1, title: '提示', btn: ['OK']});
            houseInfoListTable.fnDraw();
        })
    }

    var unfocusingClick = function (obj) {
        layer.confirm("确定要取消聚焦吗？", {
            title: '提示',
            btn: ['确认', '取消'], //按钮
            area: ['auto', 'auto'] //宽高
        }, function () {
            var result = ART.mAjax("${GLOBAL.basePath}/houseInfo/unfocusing", "POST", {houseId: $(obj).attr("pkId")});
            layer.alert("取消成功", {icon: 1, title: '提示', btn: ['OK']});
            houseInfoListTable.fnDraw();
        })
    }

    var phone = function (obj) {
        document.location.href = "${GLOBAL.basePath}/phone/list?id=" + $(obj).attr("pkId");
    }
</script>
